From: Tim Deegan Date: Thu, 7 Apr 2011 10:12:55 +0000 (+0100) Subject: x86/hvm: Don't unconditionally set up nested HVM state X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=f08e80a9df74ab40c3da0da4dc059300973e6dbf;p=xen.git x86/hvm: Don't unconditionally set up nested HVM state for domains that aren't going to use it. Signed-off-by: Tim Deegan --- diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 515614bbc8..669330fbda 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -967,18 +967,8 @@ int hvm_vcpu_initialise(struct vcpu *v) if ( (rc = hvm_funcs.vcpu_initialise(v)) != 0 ) goto fail2; - /* When I start the l1 guest with 'xm/xend' then HVM_PARAM_NESTEDHVM - * is already evaluated. - * - * When I start the l1 guest with 'xl' then HVM_PARAM_NESTEDHVM - * has not been evaluated yet so we have to initialise nested - * virtualization unconditionally here. - */ - rc = nestedhvm_vcpu_initialise(v); - if ( rc < 0 ) { - printk("%s: nestedhvm_vcpu_initialise returned %i\n", __func__, rc); + if ( (rc = nestedhvm_vcpu_initialise(v)) < 0 ) goto fail3; - } /* Create ioreq event channel. */ rc = alloc_unbound_xen_event_channel(v, 0); @@ -1046,11 +1036,7 @@ int hvm_vcpu_initialise(struct vcpu *v) void hvm_vcpu_destroy(struct vcpu *v) { - int rc; - - rc = nestedhvm_vcpu_destroy(v); - if (rc) - gdprintk(XENLOG_ERR, "nestedhvm_vcpu_destroy() failed with %i\n", rc); + nestedhvm_vcpu_destroy(v); #ifdef CONFIG_COMPAT free_compat_arg_xlat(v); @@ -3436,6 +3422,11 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg) */ if ( !paging_mode_hap(d) && a.value ) rc = -EINVAL; + /* Set up NHVM state for any vcpus that are already up */ + if ( !d->arch.hvm_domain.params[HVM_PARAM_NESTEDHVM] ) + for_each_vcpu(d, v) + if ( rc == 0 ) + rc = nestedhvm_vcpu_initialise(v); break; } @@ -4035,11 +4026,10 @@ int nhvm_vcpu_initialise(struct vcpu *v) return -EOPNOTSUPP; } -int nhvm_vcpu_destroy(struct vcpu *v) +void nhvm_vcpu_destroy(struct vcpu *v) { - if (hvm_funcs.nhvm_vcpu_destroy) - return hvm_funcs.nhvm_vcpu_destroy(v); - return -EOPNOTSUPP; + if ( hvm_funcs.nhvm_vcpu_destroy ) + hvm_funcs.nhvm_vcpu_destroy(v); } int nhvm_vcpu_reset(struct vcpu *v) diff --git a/xen/arch/x86/hvm/nestedhvm.c b/xen/arch/x86/hvm/nestedhvm.c index 601a0b9246..298f34ae1b 100644 --- a/xen/arch/x86/hvm/nestedhvm.c +++ b/xen/arch/x86/hvm/nestedhvm.c @@ -33,12 +33,8 @@ nestedhvm_enabled(struct domain *d) bool_t enabled; enabled = !!(d->arch.hvm_domain.params[HVM_PARAM_NESTEDHVM]); - /* sanity check */ BUG_ON(enabled && !is_hvm_domain(d)); - - if (!is_hvm_domain(d)) - return 0; - + return enabled; } @@ -78,8 +74,11 @@ nestedhvm_vcpu_initialise(struct vcpu *v) { int rc; - rc = nhvm_vcpu_initialise(v); - if (rc) { + if ( !nestedhvm_enabled(v->domain) ) + return 0; + + if ( (rc = nhvm_vcpu_initialise(v)) ) + { nhvm_vcpu_destroy(v); return rc; } @@ -88,13 +87,11 @@ nestedhvm_vcpu_initialise(struct vcpu *v) return 0; } -int +void nestedhvm_vcpu_destroy(struct vcpu *v) { - if (!nestedhvm_enabled(v->domain)) - return 0; - - return nhvm_vcpu_destroy(v); + if ( nestedhvm_enabled(v->domain) ) + nhvm_vcpu_destroy(v); } static void diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c index 7c9f2d0bba..425112a37e 100644 --- a/xen/arch/x86/hvm/svm/nestedsvm.c +++ b/xen/arch/x86/hvm/svm/nestedsvm.c @@ -112,7 +112,7 @@ err: return -ENOMEM; } -int nsvm_vcpu_destroy(struct vcpu *v) +void nsvm_vcpu_destroy(struct vcpu *v) { struct nestedvcpu *nv = &vcpu_nestedhvm(v); struct nestedsvm *svm = &vcpu_nestedsvm(v); @@ -134,8 +134,6 @@ int nsvm_vcpu_destroy(struct vcpu *v) } if (svm->ns_iomap) svm->ns_iomap = NULL; - - return 0; } int nsvm_vcpu_reset(struct vcpu *v) diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index 0c80f43d21..1445fd982e 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -148,7 +148,7 @@ struct hvm_function_table { /* Nested HVM */ int (*nhvm_vcpu_initialise)(struct vcpu *v); - int (*nhvm_vcpu_destroy)(struct vcpu *v); + void (*nhvm_vcpu_destroy)(struct vcpu *v); int (*nhvm_vcpu_reset)(struct vcpu *v); int (*nhvm_vcpu_hostrestore)(struct vcpu *v, struct cpu_user_regs *regs); @@ -415,7 +415,7 @@ static inline int hvm_memory_event_int3(unsigned long gla) /* Initialize vcpu's struct nestedhvm */ int nhvm_vcpu_initialise(struct vcpu *v); /* Destroy and free vcpu's struct nestedhvm */ -int nhvm_vcpu_destroy(struct vcpu *v); +void nhvm_vcpu_destroy(struct vcpu *v); /* Reset vcpu's state when l1 guest disables nested virtualization */ int nhvm_vcpu_reset(struct vcpu *v); /* Restores l1 guest state */ diff --git a/xen/include/asm-x86/hvm/nestedhvm.h b/xen/include/asm-x86/hvm/nestedhvm.h index dc7c0cc1e7..123aab3fe0 100644 --- a/xen/include/asm-x86/hvm/nestedhvm.h +++ b/xen/include/asm-x86/hvm/nestedhvm.h @@ -38,7 +38,7 @@ bool_t nestedhvm_enabled(struct domain *d); /* Nested VCPU */ int nestedhvm_vcpu_initialise(struct vcpu *v); -int nestedhvm_vcpu_destroy(struct vcpu *v); +void nestedhvm_vcpu_destroy(struct vcpu *v); void nestedhvm_vcpu_reset(struct vcpu *v); bool_t nestedhvm_vcpu_in_guestmode(struct vcpu *v); #define nestedhvm_vcpu_enter_guestmode(v) \ diff --git a/xen/include/asm-x86/hvm/svm/nestedsvm.h b/xen/include/asm-x86/hvm/svm/nestedsvm.h index 876802e521..51248315bb 100644 --- a/xen/include/asm-x86/hvm/svm/nestedsvm.h +++ b/xen/include/asm-x86/hvm/svm/nestedsvm.h @@ -100,7 +100,7 @@ nestedsvm_check_intercepts(struct vcpu *v, struct cpu_user_regs *regs, uint64_t exitcode); /* Interface methods */ -int nsvm_vcpu_destroy(struct vcpu *v); +void nsvm_vcpu_destroy(struct vcpu *v); int nsvm_vcpu_initialise(struct vcpu *v); int nsvm_vcpu_reset(struct vcpu *v); int nsvm_vcpu_hostrestore(struct vcpu *v, struct cpu_user_regs *regs);